$(document).ready(function() {
	$(".subNavigator a").click(function(){
		$(".subNavigator td.active").removeClass('active');
		$(this).parent('td').addClass('active');
	});						
});

function loadLabResults(recordId) {
	$.ajax ({
		type: 	 "GET",
		url:	 "../Laboratory/LoadLabResultAjax?set_ajax_view",
		data:	 "recordId=" + recordId,
		dataType: 'json',
		success: function(data) {
			if (data.error.code == 'OK') {				
				$('div#medicalContent').html(data.result);	
			} else {
				displayError(data.error.mess);				
			}
			
		}
	});
}

function loadRadResults(recordId) {
    $.ajax ({
        type:    "GET",
        url:     "../OutRadiology/LoadRadResultAjax?set_ajax_view",
        data:    "recordId=" + recordId,
        dataType: 'json',
        success: function(data) {
            if (data.error.code == 'OK') {              
                $('div#medicalContent').html(data.result);  
            } else {
                displayError(data.error.mess);              
            }
            
        }
    });
}

function loadOpenSurgery(recordId, message) {
	$.ajax ({
		type: 	 "GET",
		url:	 "../Surgery/loadOpenSurgeryAjax?set_ajax_view",
		data:	 "recordId=" + recordId,
		success: function(data) {
			$('#surgeryTeamTemplateDialog').remove();
			$(".subNavigator td.active").removeClass('active');
			$('#phauThuat').parent('td').addClass('active');
			$('div#medicalContent').html(data);
			if (message != '') {
				$('span#successfulMessage').text(message).css('color', 'green').show(1000);
			}				
		}
	});
}

function loadOpenPrescription(recordId) {
	$.ajax ({
		type: 	 "GET",
		url:	 "../Prescription/editPrescription?set_ajax_view",
		data:	 "recordId=" + recordId,
		beforeSend: function() {toggleModalAjaxLoader();},		
		complete: function() {toggleModalAjaxLoader();},
		success: function(data) {
			$(".subNavigator td.active").removeClass('active');
			$('#toaThuoc').parent('td').addClass('active');
			$('#medicalContent').html(data);
		}
	});
}

function loadOpenOdontologyService(recordId) {
	$.ajax ({
		type: 	 "GET",
		url:	 "../OutPayment/EditServiceListAjax?set_ajax_view",
		data:	 "recordId=" + recordId,
		beforeSend: function() {toggleModalAjaxLoader();},		
		complete: function() {toggleModalAjaxLoader();},
		success: function(data) {
			$(".subNavigator td.active").removeClass('active');
			$('#dichVu').parent('td').addClass('active');
			$('#medicalContent').html(data);
		}
	});
}

function loadOpenParaclinic(recordId) {
	$(".subNavigator td.active").removeClass('active');
	$('#canLamSang').parent('td').addClass('active');

	$.ajax ({
		type: 'POST',
		url: '../MedicalRecord/LoadCanLamSang?set_ajax_view',
		data: 'recordId=' + recordId,
		dataType: 'json',
		beforeSend: function() {toggleModalAjaxLoader();},		
		complete: function() {toggleModalAjaxLoader();},
		success: function(data) {			
			$('#medicalContent').html(data.html);
		}
	});	
}

function loadOpenDemographic(recordId) {
	$(".subNavigator td.active").removeClass('active');
	$('#hanhChinh').parent('td').addClass('active');
	
	$.ajax ({
		type: 'POST',
		url: '../MedicalRecord/LoadDemographic?set_ajax_view',
		data: 'recordId=' + recordId,
		dataType: 'json',
		beforeSend: function() {toggleModalAjaxLoader();},		
		complete: function() {toggleModalAjaxLoader();},
		success: function(data) {			
			$('#medicalContent').html(data.html);
		}
	});
	
	//$('#medicalContent').html("<div style='padding-top: 10px; font-size:2em; color: red;'>" + _('This page is under customization') + "</div>");
}

function loadOpenEncounterResults(recordId, canEditEncounter){
	$.ajax ({
		type: 	 "GET",
		url:	 "../MainEncounter/loadOpenEncounterResults?set_ajax_view",
		data:	 "recordId=" + recordId +
				 "&canEditEncounter=" + canEditEncounter,
		success: function(data) {
			$('div#medicalContent').html(data);
		}
	});
}

function viewOpenRecord(recordId, canEditEncounter) {
	
	$('#medicalSubRecordMenu').show();
	
	$('#khamLamSang').attr('href', 'javascript:loadOpenEncounterResults(' + recordId + ', ' + canEditEncounter + ')');
	$('#toaThuoc').attr('href', 'javascript:loadOpenPrescription(' + recordId + ')');
	$('#hanhChinh').attr('href', 'javascript:loadOpenDemographic(' + recordId + ')');
	$('#canLamSang').attr('href', 'javascript:loadOpenParaclinic(' + recordId + ')');
	
	$(".subNavigator td.active").removeClass('active');
	$('#khamLamSang').parent('td').addClass('active');
	
	loadOpenEncounterResults(recordId, canEditEncounter);		
}

function addRecord(viewType) {
	$.ajax({
		type:	 "GET",			
		url:	 "../MedicalRecord/AddAjax?set_ajax_view",
		data:	 "patient_id=" + $("input#patient_id").val() + '&viewType=' + viewType,
		success: function(data) {
			if (data != 'NO_TICKET') {
				$('div#pageContent').html(data);
			} else {
				$('#add_record_button').hide('fast');
				$('#noTicketFound').show('fast');
			}										
		}
	});	
}
